<template>
    <div>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" class="login-box">
        <h1 class="login-title">欢迎登录</h1>
        <el-form-item label="账号" prop="username">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input type="password" v-model="form.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="login('form')">登录</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
    </div>
</template>

<script>
    export default {
        name: "Login.vue",
      data() {
          return {
            form: {
              username: '',
              password: ''
            },
            rules: {
              username: [
                { required: true, message: '请输入账号', trigger: 'blur' } /*blur失去焦点时触发*/
              ],
              password: [
                { required: true, message: '请输入密码', trigger: 'blur' } /*blur失去焦点时触发*/
              ]
            }
          }
      },
      methods: {
          login: function (formName) {
            this.$refs[formName].validate((valid) => {
              if (valid) {
                // alert('submit!');
                this.$router.push("/main");
              } else {
                // alert('请输入账号密码');
                this.$message.error('请输入账号密码');
                return false;
              }
            });

          }
      }
    }
</script>

<style scoped>
  .login-title {
    text-align: center;
  }

  .login-box {
    /*按钮，放到左边去*/
    text-align: left;
    /*宽度*/
    width: 400px;
    /*边框*/
    border: 1px solid #DCDFE6;
    /*内边距（留白，间隙）,4个方向：上，右，下，左*/
    padding: 20px 60px 20px 20px;
    /*框框居中*/
    margin: 0 auto;
    /*框框向下一点*/
    margin-top: 150px;
    /*框框圆角*/
    border-radius: 7px;
    /*立体，阴影*/
    box-shadow: 0 0 20px;
  }
</style>
